package com.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.model.Employee;
import com.model.User;
import com.service.EmpService;
import com.util.Conversion;
import com.util.JdbcUtil;

/**
 * Servlet implementation class ShowUserServlet
 */
@WebServlet("/sus")
public class ShowUserServlet extends BaseServlet {
	
	private static final long serialVersionUID = 1L;
	   
	
	protected void query(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		JdbcUtil jdbc = new JdbcUtil();
		String sql ="select * from user";
		List<User> users = jdbc.queryPreparedStatement(sql, User.class);
			
		request.setAttribute("users",users);
		//System.out.println(emps.isEmpty());
		request.getRequestDispatcher("show_user.jsp").forward(request, response);
		
		
	}
	protected void delete(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		String uid = request.getParameter("uid");
		JdbcUtil jdbc = new JdbcUtil();
		String sql="delete from user where uid=?";
		try {
			jdbc.updatePreparedStatement(sql,uid);
			request.getRequestDispatcher("sus?action=query").forward(request, response);
		
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("mess", "删除失败，请稍后再试");
		}
	}
}
